<template>
  <div class="app-container">
    <div id="main" style="width: 2000px; height: 1000px;"></div>
  </div>
</template>

<script>
import { chartList } from "@/api/gxs/deduction";
import * as echarts from 'echarts';
import item from "../../../layout/components/Sidebar/Item";
export default {
  name: "Deduction",
  mounted() {
    this.initChart();
  },
  data() {
    return {
      // 减分表格数据
      deductionList: [],
      convertedData:[],

      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: "",
        userName: "",
        deptId: "",
        gxsYear: "",
        gxsParenttypeId: "",
        gxsSubtypeId: "",
      },

    };
  },
  created() {
    this.getList();
  },
  watch:{
    convertedData(newValue){
      this.initChart();
    }
  },

  methods: {
    /** 查询减分列表 */
    getList() {
      this.loading = true;
      chartList(this.queryParams).then(response => {
        this.deductionList = response.rows;

        console.log(this.awardList);
        this.convertedData = this.deductionList.map(item => ({ value: item.num, name: item.type }));
        console.log(this.convertedData);
      });
    },
    initChart() {
      var chartDom = document.getElementById('main');
      var myChart = echarts.init(chartDom);
      var option;

      option = {
        title: {
          text: '活动类型比例',
          left: 'center'
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          orient: 'vertical',
          left: 'left'
        },
        series: [
          {
            name: 'Access From',
            type: 'pie',
            radius: '50%',
            data: this.convertedData,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      };

      option && myChart.setOption(option);
    }

  }
};
</script>
